export const getDataByLocal = (key: string) => {
  const value = localStorage.getItem(key);
  const date = new Date();
  if (value) {
    const item = JSON.parse(value);
    const { time, data } = item;
    if (time > date.getTime()) {
      return data;
    } else {
      localStorage.removeItem(key);
    }
  }
  return null;
};

export const setData2Local = ({
  time,
  data,
  key
}: {
  time: number;
  data: any;
  key: string;
}) => {
  const date = new Date();
  localStorage.setItem(
    key,
    JSON.stringify({ time: date.getTime() + time, data })
  );
};
